import { getNowWeek } from '@/utils/formatterDate'
import { useInterval } from 'ahooks'
import { useState } from 'react'
import dayjs from 'dayjs'
import useShowName from './useShowName'

/** 获取欢迎语 */
const useWelcomeByRole = () => {
    const { showName } = useShowName()

    const roleName = showName

    /** 更新最新时间 */
    const updateWelcomeInfo = () => {
        return {
            curDayjs: dayjs(Date.now()),
            nowTime: dayjs(Date.now()).format('YYYY/MM/DD'),
            nowWeekly: getNowWeek(),
            welcome: `${Number(dayjs().format('H')) <= 12 ? '上午' : '下午'}好`,
        }
    }

    const [store, setStore] = useState(updateWelcomeInfo())

    useInterval(() => {
        setStore(updateWelcomeInfo())
    }, 1000)

    return {
        /** 角色 */
        roleName,
        /** 当前时间 */
        nowTime: store.nowTime,
        /** 当前周 */
        nowWeekly: store.nowWeekly,
        /** 换欢迎语 */
        welcome: store.welcome,
    }
}

export default useWelcomeByRole
